<?php

class Db_Book extends Model_Db_Core {

	protected  $Book   = null;
	protected  $value   = array();
	protected  $updateValue   = array();
	
	function __construct($title = null, $autor = null, $maincategory = null, $publisherid = null, $release = '0000-00-00', $original_title = null, $subcategory = null,$isbn13 = NULL,$isbn10 = NULL,$pagenumbers = NULL,$tag = NULL,$pic = NULL,$sprache = NULL,$preis = NULL,$art = NULL,$groesse = NULL,$bewertung = 0){		
		$this->value['title'] = $title;
		$this->value['original_title'] = $original_title;
		$this->value['autor'] = $autor;
		$this->value['maincategory'] = $maincategory;
		$this->value['subcategory'] = 0;
		$this->value['isbn13'] = $isbn13;
		$this->value['isbn10'] = $isbn10;
		$this->value['publisher'] = $publisherid;
		if($pagenumbers)
			$this->value['pagenumbers'] = $pagenumbers;
		else 
			$this->value['pagenumbers'] = 0;
		if($release)
			$this->value['release'] = $release;
		$this->value['tag'] = $tag;
		$this->value['pic'] = $pic;
		$this->value['sprache'] = $sprache;
		if($preis)
			$this->value['preis'] = $preis;
		$this->value['art'] = $art;
		$this->value['groesse'] = $groesse;
		$this->value['bewertung'] = $bewertung;
	}
	
	public function getBookByName($name){
	    $filter  = array('title'=> $name);
	    $select  = array();
	    
	    parent::getSQLResult(__CLASS__,$filter,$select);
	    $this->Book = parent::result();

	    return $this->Book;
	}
	public function setBook() {       
		parent::setInsert(__CLASS__);
		 	 					
	    $status = $this->writeToDb();
	    
	    return $status;
	}  
	public function getBookByNameLike($name,$limit = 5){		
	    $sql = "Select title, id From book where title like '$name%' limit $limit";
	    parent::setSqlManuel($sql);
	    $Book = parent::result();
	    return $Book;
	}
	public function updateBookWithTuppel($what,$value){
		$this->updateValue[$what] = $value;
		return true;
	}  
	public function dbUpdateBook($id){
		$tmp = array_keys($this->updateValue);
		$lastkey = array_pop($tmp);
		
	    $con = self::startGDB();
	    $sql = "UPDATE book SET ";
			foreach ($this->updateValue as $key => $value){
				if(is_numeric($value))
				{
					$sql .= "$key = $value";
				}
				else
				{
					$value = mysql_escape_string($value);
					$sql .= "$key = '$value'";
				}
				if($lastkey != $key){
					$sql .= " and ";
				}		
			}
			$sql .= " where id = $id limit 1";	
			return $con->Select($sql);
	}
	
	
	
}

?>